package com.yumeko;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @program: First_Generation_Cloud
 * @description:
 * @author: Zheng Hao
 * @create: 2020-04-20 16:45
 */
@SpringBootApplication
@EnableDiscoveryClient //开启服务发现
@EnableCircuitBreaker //开启熔断
public class AutodeliverApplication2222 {
    public static void main(String[] args) {
        SpringApplication.run(AutodeliverApplication2222.class, args);
    }

    @Bean
    //@LoadBalanced //区域权衡策略（默认策略）
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    //在被监测的微服务中注册监控servlet（⾃动投递微服务，监控数据就是来⾃于这个微服务）
    @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/actuator/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}
